<template>
	<view class="page">
		<!-- 头部搜索 -->
		<view class="header">
			<view class="searchBox">
				<u-icon name="search" style="font-size: 36rpx; color: #A8B5C5;" ></u-icon>
				<u-input v-model="keywords" height="72" style="width: 540rpx; margin-left: 16rpx;" placeholder="输入企业信息" />
				<view class="search" @click="search()">
					搜索
				</view>
			</view>
		</view>
		<!-- 公司列表项/跟进的状态 -->
		<view class="item" v-for="(item,index) in list" :key="index">
			<view class="titleBox">
				<view class="txt">
					{{item.companyName}}
				</view>
				<view class="king-flex">
					<view class="tag" v-if="item.signStatus == 0" @click="$next(`/pages/functionCore/customer/add?id=${item.id}`)">
						编辑
					</view>
					<view class="tag">
						{{statusTextArr[item.customFlowList[0].status]||'待跟进'}}
					</view>
				</view>
				
			</view>
			<!-- 编号 -->
			<view class="biaoHao" v-if="item.houseNum">
				{{item.houseNum}}
			</view>
			
			<view class="list">
				<!-- 信息标题 -->
				<view class="left">
					电&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp话
				</view>
				<view class="right">
					<view class="centent">
						{{item.companyMobile}}
					</view>
					<view class="xiangQing" @click="$next(`/pages/functionCore/customer/detail?id=${item.id}`)">
						详情 >
					</view>
				</view>
			</view>
			<view class="list">
				<!-- 信息标题 -->
				<view class="left">
					预估电量
				</view>
				<view class="right">
					<view class="centent">
					{{item.electricityNum}} Kwh
					</view>
				</view>
			</view>
			<view class="list" v-if="item.type == 1">
				<!-- 信息标题 -->
				<view class="left">
					代理人名称
				</view>
				<view class="right">
					<view class="centent">
					{{item.user.realname}}
					</view>
				</view>
			</view>
			
			<view class="list" v-if="item.type == 1">
				<!-- 信息标题 -->
				<view class="left">
					代理人电话
				</view>
				<view class="right">
					<view class="centent">
					{{item.user.mobile}}
					</view>
				</view>
			</view>
			
		</view>
		<!-- 加载更多 -->
		<u-loadmore v-if="list.length !== 0" :status="status" :load-text="loadText" />
		<image v-else src="@/static/image/empty.png" mode="widthFix" class="is-empty"></image>
		<!-- 新建按钮 -->
		<view class="add" @click="$next(`/pages/functionCore/customer/add`)">
			+
			<!-- <u-button type="primary" @getuserinfo="add">+</u-button> -->
		</view>
	</view>
</template>

<script>
export default {
    data() {
        return {
			keywords:'',
			page:1,
			limit:10,
			more:false,
			// 页面数据初始化状态
			loadText: {
				loadmore: '轻轻上拉，加载更多',
				loading: '努力加载中',
				nomore: '我也是有底线的'
			},
			list:[],
			statusTextArr:[
				'已签约',
				'意向签约',
				'待跟进',
				'暂不考虑',
				'待线上联系',
				'待分配客户',
				'无效客户'
			],
        }
    },
	mounted() {
		uni.$on('reloadData', (res) => {
			this.page = 1
			this.getCustomRes()
		})
	},
	onLoad() {
		uni.setNavigationBarTitle({
			title: `我的${uni.getStorageSync("userinfo").userType == 0 ? '客户' : '档案'}`
		})
		this.getCustomRes()
	},
	//下拉刷新
	onPullDownRefresh() {
		this.page = 1
		this.getCustomRes()
	},
	//上拉加载
	onReachBottom() {
		if (this.page == 1) {
			return
		}
		if (this.more) {
			this.getCustomRes()
		}
	},
    methods: {
	
		search(){
			this.page = 1
			this.getCustomRes()
		},
		getCustomRes(){
			this.$axios.request(this.$api.getCustomRes,"GET",{
				limit:this.limit,
				page:this.page,
				type:0,
				keywords:this.keywords,
				orderField: 'id',
				order: 'desc'
			}).then((val) => {
				uni.stopPullDownRefresh();
				this.list = this.page == 1 ? val.data.list : this.list.concat(val.data.list)
				if (Math.ceil(val.data.total / this.limit) > this.page) {
					this.more = true;
					this.page++
				} else {
					this.more = false;
				}
			})
		}
    }
}
</script>

<style>
	.page {
		width: 100%;
		/* height: 100vh; */
		overflow-y: auto;
		background-color: #f9f9f9;
	}
	.header {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100%;
		height: 120rpx;
		background-color: #FFFFFF;
		
	}
	.searchBox {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 702rpx;
		height: 72rpx;
		/* margin: 16rpx auto 16rpx; */
		background-color: #f0f0f0;
		/* background-color: red; */
	}
	.search {
		width: 90rpx;
		height: 40rpx;
		font-size: 32rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		line-height: 40rpx;
		color: #3975EA;
		border-left: 2rpx solid #A8B5C5;
		text-align: center;
		opacity: 1;
	}
	.item {
		overflow: hidden;
		width: 100%;
		/* height: 311rpx; */
		background-color: #fff;
		margin: 16rpx 0rpx;
		padding:16rpx 0rpx;
		/* padding-left: 32rpx; */
	}
	.titleBox {
		display: flex;
		justify-content: space-between;
		align-items: center;
		/* width: 750rpx; */
		height: 42rpx;
		margin-top: 16rpx;
		margin: 0rpx 32rpx;
	}
	.txt {
			height: 40rpx;
			font-size: 32rpx;
			font-family: "PingFang SC";
			font-weight: 600;
			line-height: 40rpx;
			color: #333333;
	}
	
	.tag {
		/* width: 128rpx; */
		height: 40rpx;
		margin-left:10rpx;
		font-size: 20rpx;
		font-family: "PingFang SC";
		font-weight: 400;
		line-height: 40rpx;
		color: #F5F5F5;
		/* text-align: center; */
		padding: 0 15rpx;
		background-color: #3975EA;
	}
	.biaoHao {
		height: 28rpx;
		font-size: 24rpx;
		font-family: "PingFang SC";
		font-weight: 400;
		line-height: 20rpx;
		color: #BBBBBB;
		margin: 15rpx 0 18rpx;
		margin-left: 32rpx;
	}
	
	.list {
		display: flex;
		border-bottom: 2px solid #f9f9f9;
		justify-content: space-between;
		align-items: center;
		width: 100%;
		height: 65rpx;
	}
	.list:last-child{
		border-bottom: none;
	}
	.left {
		width: 188rpx;
		height: 33rpx;
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 600;
		line-height: 33rpx;
		color: #333333;
		margin-left: 32rpx;
	}
	.right {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 590rpx;
		height: 33rpx;
	}
	.centent {
		font-size: 28rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		color: #BBBBBB;
	}
	.xiangQing {
		/* width: 71rpx; */
		height: 33rpx;
		font-size: 24rpx;
		font-family: "PingFang SC";
		font-weight: 300;
		line-height: 33rpx;
		color: #FF5D58;
		margin-right: 32rpx;
	}
	.item .list:first-child {
		border-top: 4rpx solid #F3F4F8;
	}
	.add {
		position: fixed;
		right: 36rpx;
		bottom: 102rpx;
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		font-size: 60rpx;
		line-height: 77rpx;
		text-align: center;
		color: #FFFFFF;
		background-color: #2E6ADF;
	}
</style>
